import tkinter as tk
from tkinter import ttk

class TreeViewFrame(tk.LabelFrame):
    def __init__(self, master,tbheight=20,*args ,**kwords) -> None:
        super().__init__(master, *args,**kwords)
        self.tbheight = tbheight
        self._design()
    def _design(self):
        columnss = ["idx","Item","Result","MarkLevel"]
        xscroll = tk.Scrollbar(self, orient=tk.HORIZONTAL)
        yscroll = tk.Scrollbar(self, orient=tk.VERTICAL)
        self.tvtable = ttk.Treeview(self,height=self.tbheight,columns=columnss,show='headings',selectmode='browse',yscrollcommand=yscroll.set,xscrollcommand=xscroll.set)
        xscroll.config(command=self.tvtable.xview)
        yscroll.config(command=self.tvtable.yview)
        
        self.tvtable.grid(column=0,row=0,sticky="wnse")
        yscroll.grid(column=1,row=0,sticky="ns")
        xscroll.grid(column=0,row=1,columnspan=2,sticky="we")

        [self.tvtable.heading(column=idx,text=idx) for idx in columnss]
        c_weight = [50,400,50,50]
        [self.tvtable.column(item,width=c_weight[idx],minwidth=c_weight[idx],anchor='s') if idx!=1 else self.tvtable.column(item,width=c_weight[idx],minwidth=c_weight[idx]) for idx,item in enumerate(columnss)]
        self.columnconfigure(0,weight=1)
        self.rowconfigure(0,weight=1)
    def m_InsrtData(self,data:list):
        self.tvtable.insert('','end',values=data)
    def m_ClearData(self):
        [self.tvtable.delete(idx) for idx in self.tvtable.get_children()]

if __name__=="__main__":
    win = tk.Tk()

    zx = TreeViewFrame(win)
    zx.grid(column=0,row=0,sticky="wnse")
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    zx.m_InsrtData([1,2,3,4])
    win.columnconfigure(0,weight=1)
    win.rowconfigure(0,weight=1)

    win.mainloop()